package com.bookmanger.server.mapper;

import com.bookmanger.pojo.DTO.CheckInfoDTO;
import com.bookmanger.pojo.Entity.AdminEntity;
import com.bookmanger.pojo.Entity.Reader;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SysAdminMapper {
    @Select("SELECT * FROM manager WHERE ${type}=#{info}")
    String checkInfo(CheckInfoDTO checkInfoDTO);

    @Insert("insert into manager(account,password,name,gender,age,title,type) values(#{account},#{password},#{name},#{gender},#{age},#{title},#{type})")
    void addAdmin(AdminEntity adminEntity);

    @Update("update manager set is_delete = 1 where id=#{id}")
    void deleteAdmin(Integer id);

    @Select("select * from manager where id= #{id}")
    AdminEntity findAdminById(Integer id);

    @Update("update manager set account=#{account},password=#{password},name=#{name},gender=#{gender},age=#{age},title=#{title},type=#{type} where id=#{id}")
    void updateAdminInfo(AdminEntity adminEntity);

    @Select("select * from manager where type=0")
    List<AdminEntity> findAllAdmin();

    List<AdminEntity> findAdminByInfo(String info);

    @Select("select * from reader")
    List<Reader> findAllReader();

    @Select("select  * from reader where id= #{id}")
    Reader findReaderById(Integer id);

    @Update("update reader set is_delete = 1 where id=#{id}")
    void deleteReader(Integer id);

    @Update("update reader set reader_number= #{readerNumber},password= #{password},name= #{name},department= #{department},major= #{major},grade= #{grade},phone_number= #{phoneNumber},email= #{email},gender= #{gender},status= #{status} where id= #{id}")
    void updateReaderInfoByAdmin(Reader reader);

    @Update("update reader set type_id= #{type} , status=1 where id= #{id}")
    void aggreeRegister(Integer id, Integer type);

    List<Reader> findReaderByInfo(String info);

}
